package com.yymmarket.forum.util;

import javax.servlet.http.HttpServletRequest;

import com.yymmarket.forum.cache.ForumCache;
import com.yymmarket.forum.user.UserBean;

public class SessionUtil {
	
	public static void sessionCreate(HttpServletRequest request,String name,Object value) {
		request.getSession().setAttribute(name, value);
	}
	
	public static Object getSessionAttribute(HttpServletRequest request, String name) {
		return request.getSession().getAttribute(name);
	}
	
	public static Integer getSessionUserId(HttpServletRequest request) {
		return (getSessionAttribute(request,ConstantUtil.USER_SESSION)==null)?
				0:(Integer)(getSessionAttribute(request,ConstantUtil.USER_SESSION));
	}
	
	public static UserBean getSessionUser(HttpServletRequest request) {
		int uid = getSessionUserId(request);
		return ForumCache.getUser(uid);
	}
}
